<?php
/**
 * Utility class used for working with files
 *
 * Copyright (C) 2008  Sean Hickey
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author Sean Hickey <sean@headzoo.com>
 * @version $Id: Files.php 377 2008-07-03 05:15:12Z sean $
 * @package Alinks_Files
 */
class Alinks_Files
{
	/**
	 * Similar to PHP's file_exists()
	 *
	 * Returns if the given file exists. If $check_include_path is set
	 * to true, then the method will check if the file exists any where
	 * in the include path.
	 *
	 * @param string $filename The name of the file
	 * @param bool $check_include_path To check the include path or not
	 * @return bool
	 */
	public static function exists($filename, $check_include_path = true)
	{
		$exists = file_exists($filename);
		if (false === $exists && $check_include_path) {
			$paths = explode(PATH_SEPARATOR, get_include_path());
			foreach($paths as $path) {
				$path = rtrim($path, '/\\');
				if (file_exists($path . '/' . $filename)) {
					$exists = true;
					break;
				}
			}
		}
		
		return $exists;
	}
}